/*
ONEGAME
Copyright (C) 2009  Pablo Caballero

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package one.project;

import java.awt.Dimension;
import java.util.ArrayList;
import java.util.Vector;
import one.language.Labels;
import one.map.FactoryLayerMap;
import one.map.ILayerMap;

/**
 * The default system layer section
 * @author Pablo Caballero
 * @version 1.0 22-jun-2009
 */
public class DefaultLayerManager implements ILayerManager {

    /**
     * Vector of layers
     */
    Vector<ILayerMap> layers;
    Dimension dimension;

    public DefaultLayerManager() {
        layers = new Vector<ILayerMap>(2);
        dimension = new Dimension(1, 1);
    }

    @Override
    public String toString() {
        return Labels.getString("PROJECT_SYSTEMMAPS");
    }

    public Object getChild(int index) {
        return layers.get(index);
    }

    public int getChildCount() {
        return layers.size();
    }

    public boolean isLeaf() {
        return false;
    }

    public int getLayerCount() {
        return layers.size();
    }

    public ILayerMap getLayer(int index) {
        return layers.get(index);
    }

    public void addLayer() {
        ILayerMap layer;
        layer = FactoryLayerMap.getLayerMap();
        layer.setDimension(dimension);
        layers.add(layer);
    }

    public int deleteLayers(ArrayList<ILayerMap> layers) {
        int cnt = 0;
        for (ILayerMap layer : layers) {
            if (layers.remove(layer)) {
                cnt++;
            }
        }
        return cnt;
    }

    public void resize(int width, int height) {
        dimension.setSize(width, height);
        for (ILayerMap layer : layers) {
            layer.setDimension(dimension);
        }
    }
}
